import {
  registerControlProvider,
  registerEditorProvider,
  registerPanelItemProvider,
} from '@ibiz-template/runtime';
import { withInstall } from '@ibiz-template/vue3-util';
import { App } from 'vue';
import { DRBarAnchorStyleControl } from './drbar-anchor-style/drbar-anchor-style';
import { DRBarAnchorStyleProvider } from './drbar-anchor-style/drbar-anchor-style.provider';
import { FormAnchorPointControl } from './form-anchor-point/form-anchor-point';
import { FormAnchorPointProvider } from './form-anchor-point/form-anchor-point.provider';
import { CrmPage } from './crm-page';
import ButtonBack from './button_back/button-back';
import { PanelButtonProvider } from './button_back/panel-button.provider';
import { CrmImageUpload, CrmImageUploadProvider } from './crm-image-upload';

export * from './drbar-anchor-style/drbar-anchor-style.controller';

export const IBizDRBarExControl = withInstall(
  DRBarAnchorStyleControl,
  function (v: App) {
    v.component(DRBarAnchorStyleControl.name, DRBarAnchorStyleControl);
    registerControlProvider(
      'CUSTOM_DRBAR_ANCHOR_STYLE',
      () => new DRBarAnchorStyleProvider(),
    );
  },
);

export const IBizFromAnchorPointControl = withInstall(
  FormAnchorPointControl,
  function (v: App) {
    v.component(FormAnchorPointControl.name, FormAnchorPointControl);
    registerControlProvider(
      'EDITFORM_RENDER_ANCHOR_STYLE',
      () => new FormAnchorPointProvider(),
    );
  },
);

// eslint-disable-next-line func-names
export const IBizButtonBack = withInstall(ButtonBack, function (v: App) {
  v.component(ButtonBack.name, ButtonBack);
  registerPanelItemProvider(
    'EDITOR_CUSTOMSTYLE_CRM_CALL_BACK',
    () => new PanelButtonProvider(),
  );
});

export default {
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
  install(app: App) {
    app.component(CrmPage.name, CrmPage);
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    app.use(IBizDRBarExControl as any);
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    app.use(IBizFromAnchorPointControl as any);
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    app.use(IBizButtonBack as any);
    app.component(CrmImageUpload.name, CrmImageUpload);
    registerEditorProvider(
      'EDITOR_CUSTOMSTYLE_CRM_IMAGE_UPLOAD',
      () => new CrmImageUploadProvider(),
    );
  },
};
